package com.we.wecc.aio.api;

import com.we.wecc.aw.mid.service.AwardService;
import com.we.wecc.us.db.mapper.ActUserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;

/**
 * Description:定时任务
 */
@Component
public class ScheduledTask {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Resource
    ActUserMapper actUserMapper;

    @Resource
    AwardService awardService;

    @Scheduled(cron = "0 0 0 * * ?")
    public void UpdateTimes() {
        try {
            log.info(new Date().toString());
            log.info("==================================info Times Started================================================");
            actUserMapper.updateLotteryTimes();
            actUserMapper.updateShareTimes();
            actUserMapper.updateInvestTimes();
            log.info("=========================================Update Lottery Times Over==================================");
        } catch (Exception e) {
            e.printStackTrace();
            log.info("-------------解析信息发生异常--------------");
        }
    }

    @Scheduled(cron = "0 0 22 * * ?")
    public void x() {
        int id = awardService.getCurrentAward().getId();
        awardService.x(id);
        log.info("-----------------------晚十点开奖-------------------------");
    }

    @Scheduled(cron = "0 0 10 * * ?")
    public void preheating() {
        awardService.ready();
        log.info("-----------------------早十点预热-------------------------");
    }
}
